import AudioManager from "./AudioManager";
import PeripheralSystemDataMgr from "./PeripheralSystemDataMgr";
import EventMgr from "./EventMgr";
import GameEventType from "./GameEventType";
import MatchGameData from "./MatchGameData";
import BasePageCtrl, { AnimType } from "./BasePageCtrl";
import UiManage from "./UiManage";
import MatchGameUnlockPropPage from "./MatchGameUnlockPropPage";

const { ccclass, property } = cc._decorator;

@ccclass
export default class MatchGameUnlockPropPageCtrl extends BasePageCtrl {
    @property(MatchGameUnlockPropPage)
    ui: MatchGameUnlockPropPage = null;

    rewardData: any = null;

    onLoad() {
        super.onLoad();
        this.onUILoad();
        this._animType = AnimType.SCALE;
        this._touchControl = false;
        this._hasPeneLock = true;
        this._hasBlack = true;
        this._hasTouchLock = false;
        this._hasBlackTouch = false;
        this.addButtonListen();
    }

    _init(e?) {
        AudioManager.getInstance().playMusic("get_reward_ui");
        const t = e.type;
        // const count = e.count; // Unused variable
        this.rewardData = e;
        this.ui.skillNode.children.forEach((e) => {
            e.active = false;
        });
        switch (t) {
            case MatchGameData.SkillType.Arrow:
                this.ui.arrow.active = true;
                this.ui.skillName.getComponent(cc.Label).string = "— 弓箭 —";
                break;

            case MatchGameData.SkillType.Gun:
                this.ui.skillName.getComponent(cc.Label).string = "— 大炮 —";
                this.ui.gun.active = true;
                break;

            case MatchGameData.SkillType.Hammer:
                this.ui.skillName.getComponent(cc.Label).string = "— 锤子 —";
                this.ui.hammer.active = true;
                break;
        }
    }

    start() {}

    onUILoad() {
        this.ui = this.node.addComponent(MatchGameUnlockPropPage);
    }

    addButtonListen() {
        UiManage.addButtonListen(this.ui.btn_get, this.clickGet, this);
    }

    clickGet() {
        this.hide();
        let e = this.rewardData.type;
        e = e === 1 ? 0 : e;
        EventMgr.trigger(GameEventType.SHOWEFFECT_FLYINGRED, {
            startPos: cc.v2(0, 0),
            type: e,
            callback: () => {
                PeripheralSystemDataMgr.checkShowGameStartPage(true);
            },
            reward: this.rewardData.count,
        });
    }

    clickClose() {
        this.hide();
    }
}